package cc.shacocloud.luanniao.core.service.ai.doubao

import jakarta.validation.constraints.NotBlank
import org.hibernate.validator.constraints.Length
import org.springframework.ai.chat.prompt.ChatOptions

/**
 * 豆包大模型配置属性
 * @author 思追(shaco)
 */
class DoubaoChatOptions(
    @field:NotBlank
    @field:Length(max = 255)
    private val model: String,
    private val frequencyPenalty: Float? = null,
    private val maxTokens: Int? = null,
    private val presencePenalty: Float? = null,
    private val stopSequences: MutableList<String>? = null,
    private val temperature: Float? = null,
    private val topK: Int? = null,
    private val topP: Float? = null,
) : ChatOptions {

    override fun getModel(): String {
        return model
    }

    override fun getFrequencyPenalty(): Float? {
        return frequencyPenalty
    }

    override fun getMaxTokens(): Int? {
        return maxTokens
    }

    override fun getPresencePenalty(): Float? {
        return presencePenalty
    }

    override fun getStopSequences(): MutableList<String>? {
        return stopSequences
    }

    override fun getTemperature(): Float? {
        return temperature
    }

    override fun getTopK(): Int? {
        return topK
    }

    override fun getTopP(): Float? {
        return topP
    }

    override fun copy(): ChatOptions {
        return DoubaoChatOptions(
            model = model,
            frequencyPenalty = frequencyPenalty,
            maxTokens = maxTokens,
            presencePenalty = presencePenalty,
            stopSequences = stopSequences,
            temperature = temperature,
            topK = topK,
            topP = topP
        )
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other !is DoubaoChatOptions) return false

        if (model != other.model) return false
        if (frequencyPenalty != other.frequencyPenalty) return false
        if (maxTokens != other.maxTokens) return false
        if (presencePenalty != other.presencePenalty) return false
        if (stopSequences != other.stopSequences) return false
        if (temperature != other.temperature) return false
        if (topK != other.topK) return false
        if (topP != other.topP) return false

        return true
    }

    override fun hashCode(): Int {
        var result = model.hashCode()
        result = 31 * result + (frequencyPenalty?.hashCode() ?: 0)
        result = 31 * result + (maxTokens ?: 0)
        result = 31 * result + (presencePenalty?.hashCode() ?: 0)
        result = 31 * result + (stopSequences?.hashCode() ?: 0)
        result = 31 * result + (temperature?.hashCode() ?: 0)
        result = 31 * result + (topK ?: 0)
        result = 31 * result + (topP?.hashCode() ?: 0)
        return result
    }


}